<%@page import="java.util.Calendar"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="systems.RecentlyTag"%>
<%@page import="helpers.DateHelper"%>
<%@page import="systems.RecentlyArticle"%>
<%@page import="entities.ArticleSearch"%>
<%@page import="entities.Article"%>
<%@page import="models.CategoryModel"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
CategoryModel categoryModel = CategoryModel.getInstance();
List<Category> categories = categoryModel.getAll();
List<ArticleSearch> articles = RecentlyArticle.getArticles();
List<String> tags = RecentlyTag.getTags();
String hasArchives = (String) request.getParameter("hasArchives");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
			<aside id="rightSide" class="right">
            	<div>
                    <form id="searchForm" method="get" action="/search">
						<input name="q" type="text" class="textfield" value="" placeholder="Enter content">
						<button type="submit">Search</button>
					</form>
                </div>
            	<div>
            		<script type="text/javascript"><!--
					google_ad_client = "ca-pub-2883566427648799";
					/* 300x250 */
					google_ad_slot = "2688877886";
					google_ad_width = 300;
					google_ad_height = 250;
					//-->
					</script>
					<script type="text/javascript"
					src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
					</script>
            	</div>
            	
            	<% if (hasArchives != null) { %>
            	<%
            	Calendar cal = Calendar.getInstance();
            	int currentYear = cal.get(Calendar.YEAR);
            	int year = currentYear;
            	int month = cal.get(Calendar.MONTH)+1;
            	int countMonth = DateHelper.getCountMonthFromNow(1, 2013);
            	%>
            	<div class="dateArchives clearafter">
                	<h3 class="title">Archives</h3>                    
                    <ul>
                    	<li><span><%=year %></span></li>
                    	<%
                    	for (int i = 0; i < countMonth + 1; i++) {
                    		//if (currentYear - year > 1) break;
                    	%>
                        <li><a href="/archives/<%=month <10 ? "0" + month : month %>-<%=year%>"><%=DateHelper.getMonthName(month-1) %>&nbsp;<%=year %></a></li>
                        	<%
                        	month -= 1;
                			if (month <= 0) {
                				month = 12;
                				year -= 1;
                				if (i < countMonth) {
                			%>
             		</ul>
             		<ul>
             			<li><span><%=year %></span></li>
                				<%
                				}
                			}
                        } %>                        
                    </ul>
                                        
                </div>
                <% } %>
            	
                <div class="box solidBox" itemscope itemtype="http://schema.org/ItemList">
                	<h3 class="title">Recent Articles View</h3>
                    <ul class="articleListing">
                    	<% for (int i = 0; i < articles.size(); i++) { %>
                    	<li itemscope itemtype="http://schema.org/Article" itemprop="itemListElement">
                        	<a href="/a/<%=articles.get(i).getAlias() %>" class="articleTitle" itemprop="name"><%=articles.get(i).getTitle() %></a>
                            <p class="articleMeta">Submit on <span class="date" itemprop="dateCreated"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "MMMM dd, yyyy") %></span></p>
                        </li>
                        <% } %>
                    </ul>
                </div>
                <div>
                	<h3 class="title">Categories</h3>
                    <ul class="categoryListing" itemscope itemtype="http://schema.org/ItemList">
                    	<% for (int i = 0 ; i < categories.size(); i++ ) { %>
                    	<li itemprop="itemListElement"><a itemprop="url" href="/c/<%=categories.get(i).getAlias() %>" title="Category <%=categories.get(i).getName() %>" ><span itemprop="name"><%=categories.get(i).getName() %></span></a></li>
                    	<% } %>
                    </ul>
                </div>
                <div>
                	<h3 class="title">Tags</h3>
                    <div class="tagListing" itemscope itemtype="http://schema.org/CreativeWork">
                    	<%
                    	for (int i = 0; i < tags.size(); i++) {
                    		if (i > 50) break;
                    	%>
                    	<a href="/k/<%=URLEncoder.encode(tags.get(i))%>" itemprop="keywords"><%=tags.get(i) %></a>
                    	<% } %>
                    </div>
                </div>
            </aside>